/*
 * @Author: xiaosihan
 * @Date: 2024-09-16 19:34:11
 * @Last Modified by: xiaosihan
 * @Last Modified time: 2024-09-18 01:32:49
 */

import projectCollaborationApi from "@api/projectCollaborationApi";
import { ProjectCollaborationData } from "@type";
import { get } from "lodash";
import { observable, configure } from "mobx";
configure({ enforceActions: "never" });

//项目详情
const projectDatailStore = observable(
  {
    id: "",
    createTime: "--",
    createBy: "--",
    updateTime: "--",
    updateBy: "--",
    userId: "--",
    name: "--",
    description: "--",
    status: 0,
    isPublic: 0,
    async setId(id: string = "") {
      if (id) {
        let res: any = {};
        if (/^\d+$/.test(id || "")) {
          res = await projectCollaborationApi.get_by_id(id);
        } else {
          res = await projectCollaborationApi.add_project_shareLink(id);
        }
        this.id = get(res, ["data", "id"]) || "";
        this.createTime = get(res, ["data", "createTime"]) || "--";
        this.createBy = get(res, ["data", "createBy"]) || "--";
        this.updateTime = get(res, ["data", "updateTime"]) || "--";
        this.updateBy = get(res, ["data", "updateBy"]) || "--";
        this.userId = get(res, ["data", "userId"]) || "--";
        this.name = get(res, ["data", "name"]) || "--";
        this.description = get(res, ["data", "description"]) || "--";
        this.status = get(res, ["data", "status"]) || 0;
        this.isPublic = get(res, ["data", "isPublic"]) || 0;
      }
    },
    // 修改
    async updata(projectCollaborationData: Partial<ProjectCollaborationData>) {
      await projectCollaborationApi.update(projectCollaborationData);
      this.setId(this.id);
    },
  },
  {},
  { deep: false }
);

export default projectDatailStore;
